﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using ClientWPF.BankService;

namespace ClientWPF
{
    /// <summary>
    /// Interaction logic for TransactionsWindow.xaml
    /// </summary>
    public partial class TransactionsWindow
    {
        private readonly BankServiceClient bankServiceClient;
        private string clientName;
        private readonly string clientUnp;
        private Guid clientId;
        readonly ObservableCollection<Deposit> userDeposits;

        public TransactionsWindow()
        {
            InitializeComponent();
        }

        public TransactionsWindow(BankServiceClient bankServiceClient, string clientName, string clientUnp, Guid clientId)
        {
            InitializeComponent();
            this.bankServiceClient = bankServiceClient;
            this.clientName = clientName;
            this.clientUnp = clientUnp;
            this.clientId = clientId;

            userDeposits = new ObservableCollection<Deposit>(bankServiceClient.GetClientDeposits(clientId));
            comboBoxEditPayerDepositNumber.ItemsSource = userDeposits;
            if (userDeposits.Count > 0) comboBoxEditPayerDepositNumber.SelectedIndex = 0;
        }

        private void BtnGetTransactionListClick(object sender, RoutedEventArgs e)
        {
            DepositTransactionsHistory depositTransactionsHistory = bankServiceClient.GetDepositTransactionsHistory(
                ((Deposit)comboBoxEditPayerDepositNumber.SelectedItem).Id, deDateFrom.DateTime, deDateTo.DateTime);
            IList<DepositLog> depositLogs = depositTransactionsHistory.DepositLogs;
            textBoxIncoming.Text = depositTransactionsHistory.InitialSum.ToString();
            textBoxOutgoing.Text = depositTransactionsHistory.FinalSum.ToString();
            dataGridDebetTransactions.DataContext = depositLogs.Where(x => x.IsRefill);
            dataGridCreditTransactions.DataContext = depositLogs.Where(x => !x.IsRefill);
        }
    }
}